using UnityEngine;
using System.Collections;

/// \class  gkAbyssalGiantSubmarineReduceLifeOnShockComponent
/// \brief  Make the owner loose a life when he get shocked
[AddComponentMenu("GK/AbyssalGiant/Submarine/gkAbyssalGiantSubmarineReduceLifeOnShockComponent")]
public class gkAbyssalGiantSubmarineReduceLifeOnShockComponent : MonoBehaviour 
{	
	/// The life component
	private gkLifeComponent m_rLifeComponent;
	
	/// \brief  Called just after the game begin to play
	void Start()
	{
		// Grab the life component
		m_rLifeComponent = GetComponent<gkLifeComponent>();
	}
	
	/// \brief  Called when the component is enabled
	void OnEnable() 
	{
		// Listen the shock event of the owner
		GetComponent<gkEventComponent>().AddEventHandler(gkAbyssalGiantShockEvent.ShockBegin, HandleShockBeginEvent);
	}
	
	/// \brief  Called when the component is disabled
	void OnDisable() 
	{	
		// Remove the shock event of the owner
		GetComponent<gkEventComponent>().RemoveEventHandler(gkAbyssalGiantShockEvent.ShockBegin, HandleShockBeginEvent);
	}
	
	/// Handle the begin shock event
	void HandleShockBeginEvent(Object a_rEvent)
	{
		m_rLifeComponent.DecreaseLife();
	}
}
